package com.snda.sc.auth.simple;

import java.util.HashMap;
import java.util.Map;

import com.snda.sc.auth.AuthParam;

public class SimpleParamNameBinder {

	private String key;
	private String userId;
	private String serverId;
	private String cmFlag;
	private String timestamp;
	private String sign;

	private String keyName;
	private String userIdName;
	private String serverIdName;
	private String cmFlagName;
	private String timestampName;

	private AuthParam param;

	private boolean required;

	SimpleParamNameBinder(AuthParam param, boolean required) {
		this.param = param;
		this.required = required;
	}

	Map<String, String> getSignDict() {
		Map<String, String> dict = new HashMap<>();
		dict.put(keyName, key);
		dict.put(userIdName, userId);
		dict.put(serverIdName, serverId);
		dict.put(cmFlagName, cmFlag);
		dict.put(timestampName, timestamp);
		return dict;
	}

	public SimpleParamNameBinder bindKeyName(String keyName) {
		this.keyName = keyName;
		this.key = required ? param.getRequired(keyName) : param.get(keyName);
		return this;
	}

	public SimpleParamNameBinder bindUserIdName(String userIdName) {
		this.userIdName = userIdName;
		this.userId = required ? param.getRequired(userIdName) : param.get(userIdName);
		return this;
	}

	public SimpleParamNameBinder bindServerIdName(String serverIdName) {
		this.serverIdName = serverIdName;
		this.serverId = required ? param.getRequired(serverIdName) : param.get(serverIdName);
		return this;
	}

	public SimpleParamNameBinder bindCmFlagName(String cmFlagName) {
		this.cmFlagName = cmFlagName;
		this.cmFlag = required ? param.getRequired(cmFlagName) : param.get(cmFlagName);
		return this;
	}

	public SimpleParamNameBinder bindTimestampName(String timestampName) {
		this.timestampName = timestampName;
		this.timestamp = required ? param.getRequired(timestampName) : param.get(timestampName);
		return this;
	}

	public SimpleParamNameBinder bindSignName(String signName) {
		this.sign = required ? param.getRequired(signName) : param.get(signName);
		return this;
	}

	public String getKey() {
		return key;
	}

	public String getUserId() {
		return userId;
	}

	public String getServerId() {
		return serverId;
	}

	public String getCmFlag() {
		return cmFlag;
	}

	public String getTimestamp() {
		return timestamp;
	}

	public String getSign() {
		return sign;
	}

	public String getKeyName() {
		return keyName;
	}

	public String getUserIdName() {
		return userIdName;
	}

	public String getServerIdName() {
		return serverIdName;
	}

	public String getCmFlagName() {
		return cmFlagName;
	}

	public String getTimestampName() {
		return timestampName;
	}
}
